package com.qf.dao.impl;

import com.qf.dao.CustateDao;

import com.qf.pojo.Cusstate;
import com.qf.utils.DataSourceUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class CustateDaoImpl implements CustateDao {
    QueryRunner qr= new QueryRunner(DataSourceUtil.getDataSource());

    @Override
    public List<Cusstate> findState() {
        String sql="select * from cus_state";
        try {
            return qr.query(sql,new BeanListHandler<>(Cusstate.class));
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Cusstate findStateName(int stateId) {
        String sql="select * from cus_state where state_id=?";
        try {
            return qr.query(sql,new BeanHandler<>(Cusstate.class),stateId);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
